#include "stdafx.h"
#include "IBasicSkinRenderStatic.h"
#include "BasicSkinPaintMgr.h"
#include "BasicSkinCanvas.h"

namespace BasicSkinView
{
	IBasicSkinRenderStatic::IBasicSkinRenderStatic()
	{
		m_clrText = RGB(0,0,0);
		m_pFormat = NULL;
		m_pFont = NULL;
	}
	IBasicSkinRenderStatic::~IBasicSkinRenderStatic()
	{
	}
	IBasicSkinRenderStatic* IBasicSkinRenderStatic::CreateRenderStatic(COLORREF clr)
	{
		IBasicSkinRenderStatic* pStatic = new IBasicSkinRenderStatic();
		pStatic->SetTextColor(clr);
		return pStatic;
	}

	void IBasicSkinRenderStatic::SetRenderText(const wchar_t* sz)
	{
		m_strText = sz;
	}
	void IBasicSkinRenderStatic::SetTextColor(COLORREF clr)
	{
		m_clrText = clr;
	}

	void IBasicSkinRenderStatic::SetFormat(Gdiplus::StringFormat* pFormat,bool bDel)
	{
		if(m_bDelFormat && m_pFormat)
			delete m_pFormat;
		m_pFormat = pFormat;
		m_bDelFormat = bDel;
	}

	void IBasicSkinRenderStatic::SetFormat(UINT uFormat)
	{
		Gdiplus::StringFormat* pFormat = CBasicSkinPaintMgr::GetI()->GetFormat(uFormat);
		if(pFormat != NULL)
		{
			SetFormat(pFormat,false);
		}else
		{
			pFormat = new Gdiplus::StringFormat();
			CBasicSkinPaintMgr::MakeStringFormat(*pFormat,uFormat);
			this->SetFormat(pFormat,true);
		}
	}

	void IBasicSkinRenderStatic::SetFont(Gdiplus::Font* pFont,bool bDel)
	{
		if (m_bDelFont && m_pFont)
			delete m_pFont;
		m_pFont = pFont;
		m_bDelFont = bDel;
	}

	void IBasicSkinRenderStatic::OnRenderObject(CBasicSkinCanvas* pCanvas,RECT* prc)
	{
		OnRenderText(pCanvas,prc,m_strText.c_str());
	}
	void IBasicSkinRenderStatic::OnRenderText(CBasicSkinCanvas* pCanvas,RECT* prc,const wchar_t* szText)
	{
		pCanvas->DrawSystemTextEx(szText,prc,m_pFont,m_pFormat,m_clrText);
	}
}